package cn.anlucky.apiadmin.exception;

import cn.anlucky.apiadmin.pojo.CustomException;
import cn.anlucky.apiadmin.vo.R;
import cn.dev33.satoken.exception.NotLoginException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = CustomException.class)
    public R handlerException(CustomException e) {
        e.printStackTrace();
        return R.error(e.getMessage());
    }

    /**
     * 未登录异常 Token失效异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = NotLoginException.class)
    public R handlerException(NotLoginException e) {
        e.printStackTrace();
        return R.error(5001,e.getMessage(),null);
    }
    @ExceptionHandler(value = Exception.class)
    public R handlerException(Exception e) {
        e.printStackTrace();
        return R.error(e.getMessage());
    }

}
